import os, sys

# 导入其他模块文件
project_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../database"))
if project_path not in sys.path:
    sys.path.append(project_path)

import database.database_mysql as db
import akshare as ak
import datetime
import utils.date_util as dt
import pandas as pd

# 指数

# 历史行情数据-通用
# 描述: 东方财富网-中国股票指数-行情数据
def index_zh_a_hist(
        symbol: str = "000001",
        start_date: str = "20240101",
        end_date: str = "20240401",
        period: str = "daily",
) -> pd.DataFrame:
    index_zh_a_hist_df = ak.index_zh_a_hist(symbol=symbol, period=period, start_date=start_date, end_date=end_date)
    # print(index_zh_a_hist_df)
    # index_zh_a_hist_df.to_excel(file_path + file_name, index=False)
    # stock_zh_a_spot_em_df.columns = self.stock_data_columns
    # index_zh_a_hist_columns = ['日期', '开盘', '收盘', '最高', '最低', '成交量', '成交额', '振幅', '涨跌幅',
    #                                 '涨跌额', '换手率']
    index_zh_a_hist_df.columns = ['dt', 'kp', 'sp', 'highest', 'lowest', 'cj_num', 'cj_amt', 'zf', 'zd_range',
                                    'zd_amt', 'hs_rate']
    index_zh_a_hist_df['code'] = symbol
    index_zh_a_hist_df['name'] = '深证成指'
    index_zh_a_hist_df['type'] = '01'
    return index_zh_a_hist_df



# curr_date = dt.DateUtil().get_date_strftime(strftime='%Y%m%d')
# print(curr_date)

# stock_data = index_zh_a_hist(end_date=curr_date, symbol='399001')

# stock_dict = stock_data.iloc[:, 1:2]
# print(stock_data)

# test = db.MySQLHandler()
# test.insert_batch_df(df=stock_data, table_name='stock_index_his')


